package com.example.util.common;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.tomcat.util.http.fileupload.FileUtils;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.rmi.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @see
 * @author tianjintai
 * @version v1.0
 */
@Slf4j
public class StringCommonUtils {
	private static final String emptystr = "";
	private static final Pattern pattern = Pattern.compile("^http://(.*?)\\/");
	private static final Pattern patterns = Pattern.compile("^https://(.*?)\\/");
	// 2节域名后缀的前面那节
	public static final String com[] = {"com", "net", "org", "gov", "co", "me", "edu"};
	// 以.cn结尾的2节域名后缀(各省)
	public static final String cn[] = {"tj", "ln", "sh", "sd", "sc", "yn", "xz", "sx", "qh", "xj", "ac", "ah", "bj", "cq", "fj", "gd", "gs", "gx", "gz", "ha", "hb", "he", "hi",
		"hk", "hl", "hn", "jl", "js", "jx", "ln", "mo", "nm", "nx", "zj"};
	public static final char c_g = '/';

	public static String regEx_dv1 = "//@([\\s\\S]*?)(:| |　)";// 以:或 结尾
	public static String regEx_dv2 = "//@([\u4e00-\u9fa5a-zA-Z0-9]*?)$";// 末尾是//@测试
	public static String regEx_dv3 = "@(.*?)[ |:|　]";// 或者昵称
	public static Pattern pattern_dv1 = Pattern.compile(regEx_dv1);
	public static Pattern pattern_dv2 = Pattern.compile(regEx_dv2);
	public static Pattern pattern_dv3 = Pattern.compile(regEx_dv3);

	public static final Pattern TAG_IMG = Pattern.compile("<(img|IMG) [_|src|a-zA-Z0-9| ](.*?)(\"| |/)>");
	public static final Pattern TAG_ZHUSHI = Pattern.compile("<!--.[^-]*(?=-->)-->");
	public static final Pattern TAG_A = Pattern.compile("<(a|A) [href|HREF|class|a-zA-Z0-9| ](.*?)\">");
	public static final Pattern TAG_DIV = Pattern.compile("<(div|DIV) [a-zA-Z0-9| ](.*?)>");
	public static final Pattern TAG_VEDIO = Pattern.compile("<(video|VIDEO) [a-zA-Z0-9| ](.*?)>");
	public static final Pattern TAG_VEDIO_SOURCE = Pattern.compile("<(source) [a-zA-Z0-9| ](.*?)>");
	public static final Pattern TAG_P = Pattern.compile("<(p|P) [a-zA-Z0-9| ](.*?)\">");
	public static final Pattern TAG_SECTION = Pattern.compile("<(section) [a-zA-Z0-9| ](.*?)\">");
	public static final Pattern TAG_QQMUSIC = Pattern.compile("<(qqmusic) [a-zA-Z0-9| ](.*?)\">");
	public static final Pattern TAG_STRONG = Pattern.compile("<(strong) [a-zA-Z0-9| ](.*?)\">");

	public static final Pattern TAG_SPAN = Pattern.compile("<(span|SPAN) [a-zA-Z0-9| ](.*?)\">");
	public static final Pattern TAG_BR = Pattern.compile("<[br| |/|BR|div|DIV|p|P|span|SPAN|video](.?){0,3}(p|P|span|SPAN|DIV|BR|div|br| |p|video)>");

    public static final String URL_DELIMITER = "/";
    public static final String WORLD_WIDE_WEB_PREFIX = "www.";
    public static final String HTTP_PREFIX = "http://";
    public static final String HTTPS_PREFIX = "https://";

	public static String removeContentZhushi(String content) {

		content = removeTag(content, TAG_ZHUSHI);
		return content.trim();

	}

	public static <T> List<List<T>> listGroup(List<T> source, int n) {
		if (null == source || source.size() == 0 || n <= 0) {
			return null;
		}
		List<List<T>> result = new ArrayList<List<T>>();
		int remainder = source.size() % n;
		int size = (source.size() / n);
		for (int i = 0; i < size; i++) {
			List<T> subset = null;
			subset = source.subList(i * n, (i + 1) * n);
			result.add(subset);
		}
		if (remainder > 0) {
			List<T> subset = null;
			subset = source.subList(size * n, size * n + remainder);
			result.add(subset);
		}
		return result;
	}

	public static String decodeUnicode(String asciicode) {
		String[] asciis = asciicode.split("\\\\u");
		String nativeValue = asciis[0];
		try {
			for (int i = 1; i < asciis.length; i++) {
				String code = asciis[i];
				nativeValue += (char) Integer.parseInt(code.substring(0, 4), 16);
				if (code.length() > 4) {
					nativeValue += code.substring(4, code.length());
				}
			}
		} catch (NumberFormatException e) {
			return asciicode;
		}
		return nativeValue;
	}

    /**
     * 去除string换行及特殊符号
     * @param content
     * @return
     */
	public static String removeSpecial(String content){
		return content.replaceAll("[\b\r\n\t]*", "")
				.replace("{", "")
				.replace("}", "")
				.replace("[", "")
				.replace("]", "")
				.replace("\"", "");
	}

	public static String removeHTML(String content) {

		content = content.replace("\r", "");
		content = content.replace("\n", "");
		content = removeTag(content, TAG_SECTION);
		content = removeTag(content, TAG_QQMUSIC);
		content = removeTag(content, TAG_STRONG);
		content = removeTag(content, TAG_DIV);
		content = removeTag(content, TAG_VEDIO);
		content = removeTag(content, TAG_VEDIO_SOURCE);
		content = removeTag(content, TAG_A);
		content = removeTag(content, TAG_ZHUSHI);
		content = removeTag(content, TAG_IMG);

		content = removeTag(content, TAG_SPAN);
		content = removeTag(content, TAG_P);
		content = removeTag(content, TAG_BR);

		content = content.replace("&nbsp;", "");

		content = content.replace("<strong>", " ");
		content = content.replace("</strong>", " ");

		content = content.replace("<p>", " ");
		content = content.replace("<P>", " ");
		content = content.replace("<span>", " ");
		content = content.replace("<br>", " ");
		content = content.replace("<br/>", " ");
		content = content.replace("</a>", " ");
		content = content.replace("<div>", " ");
		content = content.replace("<br />", " ");
		content = content.replace("\r\n", "");
		content = content.replace("\r", "");
		content = content.replace("\n", "");
		// content = content.replaceAll("(https|http|HTTPS|HTTP)://[^\u4e00-\u9fa5,,’\"“、]{4,1024}", "");

		content = content.replace("&nbsp;", "");
		// content = content.replaceAll("(https|http|HTTPS|HTTP)://[^\u4e00-\u9fa5,,’\"“、]{4,1024}", "");

		return content.trim();

	}

	public static String removeHTTP(String content) {
		content = content.replaceAll("(https|http|HTTPS|HTTP)://[^\u4e00-\u9fa5,,’\"“、]{4,1024}", "");
		return content.trim();

	}

	public static String removeTag(String content, Pattern tag) {
		if (content.indexOf("<") == -1 || content.indexOf(">") == -1) {
			return content;
		}
		Matcher mat = tag.matcher(content);
		while (mat.find()) {
			String temp = mat.group();

			// 把<br> 替换成空格，再计算，解决出现连在一起也会切词的问题 :将军山上<br>高海拔
			content = content.replace(temp, " ");
		}
		// if (tag.pattern().indexOf("img|IMG") > -1) {
		// content = content.replace("</IMG>", "");
		// content = content.replace("</img>", "");
		// } else if (tag.pattern().indexOf("div|DIV") > -1) {
		// content = content.replace("</DIV>", "");
		// content = content.replace("</div>", "");
		// } else if (tag.pattern().indexOf("a|A") > -1) {
		// content = content.replace("</A>", "");
		// content = content.replace("</a>", "");
		// }
		// if (content.indexOf("&nbsp;") > -1) {
		// content = content.replace("&nbsp;", " ");
		// }

		return content;
	}

	/**
	 * @see 获取网址对应域名的编码
	 * @param url
	 *            must begin with 'http://'
	 * @return String
	 */
	public static String getBaseUrlCode(String url) {
		long code = hsval(getBaseUrl(url));
		return (code + "").replace("-", "0");
	}

	/**
	 * @see 获取网址的编码
	 * @param url
	 *            must begin with 'http://'
	 * @return String
	 */
	public static String getUrlCode(String url) {
		if (StringCommonUtils.formatString(url).equals(""))
			return emptystr;
		if (url.indexOf("/", 12) == -1) {
			url = url + "/";
		}
		long code = hsval(url);
		return (code + "").replace("-", "0");
	}

	/**
	 * @see 获取网址的编码
	 * @param url
	 *            must begin with 'http://'
	 * @return String
	 */
	public static String getWebNameCode(String name) {
		if (StringCommonUtils.formatString(name).equals(""))
			return emptystr;
		long code = hsval(name);
		return (code + "").replace("-", "0");
	}

	/**
	 * @see 域名提取
	 * @param url
	 * @return String
	 */
	public static String getBaseUrl(String url) {
		if (StringCommonUtils.formatString(url).equals(""))
			return emptystr;
		if (url.indexOf("/", 12) == -1) {
			url = url + "/";
		}
		Matcher matcher = pattern.matcher(url);
		if (matcher.find()) {
			return matcher.group(1);
		}

		Matcher matchers = patterns.matcher(url);
		if (matchers.find()) {
			return matchers.group(1);
		}
		return emptystr;
	}

	/**
	 * 获取最后一节
	 *
	 * @param url
	 * @return String
	 */
	public static String getLastPathOne(String url) {
		String newURL = url.substring(0, url.lastIndexOf("/") + 1);
		if (newURL.length() > 8) {
			String domain = getDomain(newURL);
			if ((domain.length() + 1) == newURL.length()) {
				return domain;
			}
			return newURL;
		}
		return url;
	}

	public static List<String> getLastPath(String url) {
		// url="http://www.df3.gov.cn/";
		List<String> list = new ArrayList<String>();
		String newURL = url;
		for (int i = 0; i < 50; i++) {
			int len = newURL.length();
			if (newURL.lastIndexOf("/") > 8) {
				if (newURL.lastIndexOf("/") == (len - 1)) {
					if (!list.contains(newURL)) {
						list.add(newURL);
					}
					newURL = newURL.substring(0, len - 1);
					continue;

				}
				if (len >= (newURL.lastIndexOf("/") + 1)) {
					newURL = newURL.substring(0, newURL.lastIndexOf("/") + 1);
					if (newURL.length() > 8) {
						list.add(newURL);
					}
				}
			} else {
				break;
			}
		}
		if (list.size() == 0) {
			list.add(url);
		}
		return list;
	}

	/**
	 * 域名提取http://www.baidu.com/blog/1 -->http://www.baidu.com
	 *
	 * @param url
	 * @return String
	 */
	public static String getDomain(String url) {
		try {
			if (url == null || url.equals("")) {
				return "";
			}
			if (url != null) {
				url = url.trim();
			}
			if (url.toLowerCase().indexOf("http://") == -1 && url.toLowerCase().indexOf("https://") == -1) {
				url = "http://" + url;
			}
			String old = url;
			String token[] = {"http://", "https://"};
			Boolean bool = false;
			for (int i = 0; i < token.length; i++) {
				if (url.toLowerCase().indexOf(token[i]) == 0) {
					// 域名不区分大小写,路径等分大小写
					url = url.toLowerCase().replace(token[i], "");
					bool = true;
				}
			}
			// 地址里没有以http://开头
			if (!bool) {
				old = "http://" + old;
			}
			// 拿到www.baidu.com
			if (url.indexOf("/") > -1) {
				url = url.substring(0, url.indexOf("/"));
			}

			// 把http拼起来,substring(0,length(http://)+length(url))
			url = old.substring(0, old.toLowerCase().indexOf(url.toLowerCase()) + url.length());
			return url;
		} catch (Exception e) {
			log.error("url:" + url);
			log.error(e.getMessage(), e);
		}
		return url;
	}

    /**
     * 获取取出http url
     *   http://www.baidu.com/blog/1 -->http://www.baidu.com/blog/1
     *    https://www.baidu.com/blog/1  -->http://www.baidu.com/blog/1
     *      https://www.baidu.com/   -->  www.baidu.com
     *
     * @param url
     * @return
     */

    public static String getRemoveHttpUrl(String url) {
        if (url == null) {
            return null;
        }
        url = url.toLowerCase().trim();
        if (url.startsWith(HTTP_PREFIX) || url.startsWith(HTTPS_PREFIX)) {
            String newUrl = url.replace(HTTPS_PREFIX,"").replace(HTTP_PREFIX,"").toLowerCase();
            if (newUrl.contains(URL_DELIMITER) && newUrl.indexOf(URL_DELIMITER) == newUrl.length() - 1) {
                newUrl = newUrl.substring(0,newUrl.length() - 1);
            }
            return newUrl;
        }
        return url;
    }

    /**
     *   http://www.baidu.com/blog/1 -->baidu.com/blog/1
     *    https://www.baidu.com/blog/1  -->baidu.com/blog/1
     *      https://www.baidu.com/   -->  baidu.com
     * @param url
     * @return
     */
    public static String getRemoveHttpAndWwwUrl(String url) {
        if (url == null) {
            return null;
        }
        String temp_url = getRemoveHttpUrl(url);
        if (temp_url.startsWith(WORLD_WIDE_WEB_PREFIX)) {
            temp_url = temp_url.substring(temp_url.indexOf(WORLD_WIDE_WEB_PREFIX) + 4,temp_url.length());
        }
        return temp_url;
    }

    /**
     * 根据url 获取主域名
     *      http://bbs.baidu.com/blog/1 -->bbs.baidu.com
     *         https://www.baidu.com/blog/1  -->baidu.com
     *          https://www.baidu.com/   -->  baidu.com
     * @param s
     * @return
     */
    public static String getDomainByUrl(String s) {
        String temp_url = getRemoveHttpAndWwwUrl(s);
        if (temp_url.contains(URL_DELIMITER)) {
            return temp_url.substring(0,temp_url.indexOf(URL_DELIMITER));
        } else {
            return temp_url;
        }
    }


	/**
	 * 有问题
	 *
	 * @param url
	 * @return List<String>
	 */
	public static List<String> getDomainList_Error(String url) {
		List<String> list = new Vector<String>();
		// url="http://aa.bb.baidu.com/123456/89988998";
		// 子域名
		String domain = getDomain(url);
		// 顶级域名
		String domainMain = getDomainMain(url);
		String head = domain.split("//")[0];
		if (domain.split("//").length < 2) {
			return list;
		}
		String main = domain.split("//")[1];
		if (main.equals(domainMain)) {
			list.add(head + "//" + domainMain);
		} else {
			list.add(head + "//" + domainMain);
			String left = domain.substring(0, domain.lastIndexOf(domainMain) - 1).split("//")[1];
			String[] left_arr = left.split("\\.");
			String a = "";
			for (int i = left_arr.length - 1; i >= 0; i--) {

				if (!a.equals("")) {
					a = a + ".";
				}
				a = a + left_arr[i];
				String s = head + "//" + a + "." + domainMain;
				list.add(s);
			}
		}
		return list;
	}

	public static List<String> getDomainList(String url) {
		List<String> list = new Vector<String>();
		// url="http://aa.bb.baidu.com/123456/89988998";
		// 子域名
		String domain = getDomain(url);
		// 顶级域名
		String domainMain = getDomainMain(url);
		String head = domain.split("//")[0];
		if (domain.split("//").length < 2) {
			return list;
		}
		Integer a1 = domain.lastIndexOf(domainMain);
		String _domain = domain.substring(0, a1);
		if (_domain.split("//").length <= 1) {
			list.add(head + "//" + domainMain);
			return list;
		}
		String main = _domain.split("//")[1];
		String arr[] = main.split("\\.");
		for (int i = 0; i < arr.length; i++) {
			StringBuffer buff = new StringBuffer();
			for (int ii = i; ii < arr.length; ii++) {
				String s = arr[ii];
				buff.append(s);
				buff.append(".");
			}
			buff.append(domainMain);
			list.add(head + "//" + buff.toString());
		}
		list.add(head + "//" + domainMain);
		list = sortListMin(list);
		return list;
	}

	/**
	 * 按内容长度大到小排序
	 *
	 * @param aa
	 * @return List<String>
	 */
	public static List<String> sortListMax(List<String> aa) {
		Collections.sort(aa);
		Object ada[] = aa.toArray();
		List<String> rslist = new ArrayList<String>();
		for (int i = 0; i < ada.length; i++) {
			for (int ii = 0; ii < ada.length - 1; ii++) {
				String s1 = (String)ada[ii];
				String s2 = (String)ada[ii + 1];
				if (s1.length() < s2.length()) {
					ada[ii] = s2;
					ada[ii + 1] = s1;
				}
			}
		}
		for (int ia = 0; ia < ada.length; ia++) {
			String s1 = (String)ada[ia];
			rslist.add(s1);
		}
		return rslist;
	}

	/**
	 * 按内容长度大到小排序
	 *
	 * @param aa
	 * @return List<String>
	 */
	public static List<String> sortListMaxWWW(List<String> aa) {
		String c = "";
		String arr[] = {"wwwwww.", "wwwww.", "wwww.", "www."};
		for (int i = 0; i < aa.size(); i++) {
			String s = aa.get(i);
			if (s.indexOf("w.") > -1) {
				for (int j = 0; j < arr.length; j++) {
					Integer in = s.indexOf(arr[j]);
					if (in > -1) {
						aa.set(i, s.replace(arr[j], "z."));
						c = arr[j];
						break;
					}
				}

			}

		}
		Collections.sort(aa);
		Object ada[] = aa.toArray();
		List<String> rslist = new ArrayList<String>();
		for (int i = 0; i < ada.length; i++) {
			for (int ii = 0; ii < ada.length - 1; ii++) {
				String s1 = (String)ada[ii];
				String s2 = (String)ada[ii + 1];
				if (s1.length() < s2.length()) {
					ada[ii] = s2;
					ada[ii + 1] = s1;
				}
			}
		}
		for (int ia = 0; ia < ada.length; ia++) {
			String s1 = (String)ada[ia];
			s1 = s1.replace("z.", c);
			rslist.add(s1);
		}
		return rslist;
	}

	/**
	 * 按内容长度大到小排序
	 *
	 * @param aa
	 * @return List<String>
	 */
	public static List<String> sortListMin(List<String> aa) {
		Collections.sort(aa);
		Object ada[] = aa.toArray();
		List<String> rslist = new ArrayList<String>();
		for (int i = 0; i < ada.length; i++) {
			for (int ii = 0; ii < ada.length - 1; ii++) {
				String s1 = (String)ada[ii];
				String s2 = (String)ada[ii + 1];
				if (s1.length() > s2.length()) {
					ada[ii] = s2;
					ada[ii + 1] = s1;
				}
			}
		}
		for (int ia = 0; ia < ada.length; ia++) {
			String s1 = (String)ada[ia];
			rslist.add(s1);
		}
		return rslist;
	}

	/**
	 * 获取域名(不拿http://)
	 *
	 * @param url
	 * @return String
	 */
	public static String getDomainLast(String url) {

		String newUrl = getDomain(url);
		if (newUrl != null) {
			newUrl = newUrl.replace("http://", "");
			newUrl = newUrl.replace("https://", "");
		}

		return newUrl;
	}

	/**
	 * 获取域名(不拿http://)
	 *
	 * @param url
	 * @return String
	 */
	public static String getDomainLastNoPort(String url) {

		String newUrl = getDomainLast(url);
		if (newUrl.indexOf(":") > 0) {
			newUrl = newUrl.substring(0, newUrl.indexOf(":"));
		}

		return newUrl;
	}

	/**
	 * 把子域名变为*[每次只处理最后一级域名,返回值带http://]
	 *
	 * @param url
	 * @return String
	 */
	public static String[] getLevel1Domain(String url) {
		try {
			// System.out.println(url);
			// url="http://www.people.com.cn/nn/123";
			String domain = getDomain(url);
			if (domain.equals("")) {
				return null;
			}
			String arraay[] = domain.split("//");
			if (arraay.length < 2) {
				return new String[] {domain};
			}
			// ip
			String tmp = domain.replace(".", "");
			if ((domain.length() - tmp.length()) == 3) {
				tmp = tmp.replace("https://", "");
				tmp = tmp.replace("http://", "");
				if (StringCommonUtils.isNumeric(tmp)) {
					return new String[] {domain};
				}
			}
			String right = arraay[1];
			String right_p[] = right.split("\\.");
			int pointL = right_p.length;
			if (pointL <= 2) {
				return new String[] {domain};
			}
			int p = pointL - 2;
			String mainDoamin = getDomainMain(right);
			int index = right.lastIndexOf(mainDoamin);
			if (index == 0) {
				return new String[] {mainDoamin};
			}
			String left = right.substring(0, index - 1);
			String leftArray[] = left.split("\\.");
			String rzArray[] = new String[leftArray.length];
			for (int i = 0; i < leftArray.length; i++) {
				StringBuffer buff = new StringBuffer();
				for (int j = 0; j < leftArray.length; j++) {
					if (j > 0) {
						buff.append(".");
					}
					if (j <= i) {
						buff.append("*");
					} else {
						buff.append(leftArray[j]);
					}
				}
				rzArray[i] = arraay[0] + "//" + buff + "." + mainDoamin;
				// System.out.println(rzArray[i]);
			}
			return rzArray;
			// String rzArray[]=new String[pointL+p-2];
			// for (int j = 0; j < rzArray.length; j++) {
			// //把2子域名变为*
			// StringBuffer buff=new StringBuffer();
			// for (int i = 0; i < pointL; i++) {
			// if((pointL-3-i+p)>-1&&i<=j){
			// buff.append("*");
			// }else{
			// buff.append(right_p[i]);
			// }
			// if(i<(pointL-1)){
			// buff.append(".");
			// }
			// }
			// rzArray[j]=arraay[0]+"//"+buff.toString();
			// }
		} catch (Exception e) {
			log.error("url:" + url);
			log.error(e.getMessage(), e);
		}
		return null;
	}

	/**
	 * 获取是否是http://
	 *
	 * @param url
	 * @return String
	 */
	public static String getUrlHttp(String url) {
		if (url.length() < 7) {
			return "";
		}
		String token[] = {"http://", "https://"};
		for (int i = 0; i < token.length; i++) {
			if (url.toLowerCase().substring(0, 7).equals(token[i])) {
				return token[i];
			}
		}
		return "http://";
	}

	/**
	 * @see 计算code
	 * @param h
	 * @return long
	 */
	private static long strcode(int h) {
		h ^= (h >>> 20) ^ (h >>> 12);
		return h ^ (h >>> 7) ^ (h >>> 4);
	}

	public static long hsval(String stream) {
		if (null == stream) {
			return 0;
		}
		return strcode(stream.hashCode());
	}

	/**
	 * @see 读取资源文件
	 * @param paramString
	 * @return
	 */
	public static Properties getProperties(String paramString) {
		Properties localProperties = null;
		try {
			InputStream localInputStream = StringCommonUtils.class.getResourceAsStream(paramString);
			localProperties = new Properties();
			localProperties.load(localInputStream);
			localInputStream.close();
		} catch (Exception localException) {
			localException.printStackTrace();
		}
		return localProperties;
	}

	/**
	 * 只把最小那一级改为 *
	 *
	 * @param url
	 * @return String
	 */
	public static String getChildDoamin(String url) {
		try {
			String array[] = getLevel1Domain(url);
			if (array != null && array.length > 0) {
				return array[0];
			}
			// String domain=getDomain(url);
			// String com_=domain.substring(domain.lastIndexOf(".")+1,domain.length());
			// for (int i = 0; i < com.length; i++) {
			// if(domain.lastIndexOf(com[i])==domain.length()-com[i].length())
			// {
			// com_=com[i];
			// break;
			// }
			// }
			// String exccom=getExceptionCom(domain);
			// if(!exccom.equals("")){
			// com_=exccom;
			// }
			// if((url.split("\\.").length)>=2){
			// String temp=domain.replace("."+com_, "");
			// if(temp.indexOf(".")>-1){
			// String newUrl=temp.substring(0,temp.indexOf("//")+2);
			// String lastUrl=url.substring(temp.lastIndexOf("."),temp.length());
			// return newUrl+"*"+lastUrl+"."+com_;
			// }
			// return domain;
			// }
			return url;
		} catch (Exception e) {
			log.error("url:" + url);
			log.error(e.getMessage(), e);
		}
		return url;
	}

	public static long formatLong(Object obj) {
		if (obj == null) {
			return 0L;
		}
		try {
			if (obj.toString().indexOf(",") > -1) {
				obj = obj.toString().replace(",", "");
			}
			if ("".equals(obj.toString())) {
				return 0L;
			} else {
				return Long.valueOf(obj.toString());
			}
		} catch (Exception e) {
			// e.printStackTrace();
			log.info(obj + " to long error !!");
			return 0;
		}
	}

	public static int formatint(Object obj) {
		if (obj == null) {
			return 0;
		}
		try {
			if (obj.toString().indexOf(",") > -1) {
				obj = obj.toString().replace(",", "");
			}
			if ("".equals(obj.toString())) {
				return 0;
			} else if (obj.toString().indexOf(".") > -1) {
				obj = obj.toString().substring(0, obj.toString().indexOf("."));
			}
		} catch (Exception e) {
			// e.printStackTrace();
			log.info(obj + " to int error !!");
			return 0;
		}
		return Integer.parseInt(obj.toString());
	}

	public static String formatString(Object obj) {
		if (obj == null) {
			return "";
		} else {
			return obj.toString();
		}
	}

	public static boolean isZimu(String fstrData) {
		char c = fstrData.charAt(0);
		if (((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) {
			return true;
		} else {
			return false;
		}
	}

	public static Short formatShort(Object obj) {
		if (obj == null) {
			return 0;
		}
		try {
			if (obj.toString().indexOf(",") > -1) {
				obj = obj.toString().replace(",", "");
			}
			if ("".equals(obj.toString())) {
				return 0;
			} else if (obj.toString().indexOf(".") > -1) {
				obj = obj.toString().substring(0, obj.toString().indexOf("."));
			}
		} catch (Exception e) {
			// e.printStackTrace();
			log.info(obj + " to Short error !!");
			return 0;
		}
		return Short.parseShort(obj.toString());
	}

	public static boolean isNumeric(String str) {
		if (str == null) {
			return false;
		}
		for (int i = str.length(); --i >= 0;) {
			if (!Character.isDigit(str.charAt(i))) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 获取顶级域名
	 *
	 * @param url
	 * @return String
	 */
	public static String getDomainMain(String url) {
		String domain = StringCommonUtils.getDomain(url);
		try {
			if (domain.equals("")) {
				return "";
			}
			domain = domain.split("//")[1];
		} catch (Exception e) {
			log.error(url);
			log.error(domain);
			return domain;
		}
		String array[] = domain.split("\\.");
		if (array.length == 1) {
			return domain;
		}
		if (array.length == 4) {
			Boolean isNumeric = true;
			for (int i = 0; i < array.length; i++) {
				if (!isNumeric(array[i].replace(":", ""))) {
					isNumeric = false;
					break;
				}
			}
			if (isNumeric) {
				return domain;
			}
		}
		// for (int i = 0; i < p.length; i++) {
		// 正常状态
		Boolean oneSuffix = true;
		for (int j = 0; j < com.length; j++) {
			if (com[j].equals(array[array.length - 2])) {
				oneSuffix = false;
				// baidu.com.com 后缀重复了
				// if(com[j].equals(array[array.length-1])){
				// oneSuffix=true;
				// }
				break;
			}
		}
		// }
		// 处理后缀是com随便2个组成时(为正常状态)
		if (!oneSuffix) {
			for (int j = 0; j < com.length; j++) {
				if (com[j].equals(array[array.length - 1])) {
					oneSuffix = true;
					break;
				}
			}
		}
		// 各省份的sh.cn的域名
		if (oneSuffix) {
			for (int j = 0; j < cn.length; j++) {
				if (cn[j].equals(array[array.length - 2])) {
					if ("cn".equals(array[array.length - 1])) {
						oneSuffix = false;
						break;
					}
				}
			}
		}
		StringBuffer buff = new StringBuffer();
		int start = array.length - 2;
		if (!oneSuffix) {
			start = start - 1;
		}
		if (start == -1) {
			return domain;
		}
		for (int i = start; i < array.length; i++) {
			if (i > start) {
				buff.append(".");
			}
			buff.append(array[i]);
		}

		return buff.toString();
	}

	/**
	 * 获取顶级域名
	 *
	 * @param url
	 * @return String
	 */
	public static String getDomainMainNoPort(String url) {
		String domain = StringCommonUtils.getDomainMain(url);

		if (domain.indexOf(":") > 0) {
			domain = domain.substring(0, domain.indexOf(":"));
		}

		return domain;
	}

	// public static String getExceptionCom(String domain)
	// {
	// try {
	// for (int i = 0; i < exceptionCom.length; i++) {
	// int start=domain.lastIndexOf(exceptionCom[i]);
	// if(start>7){
	// int lastLen=domain.length()-start-exceptionCom[i].length();
	// if(lastLen>0&&lastLen<=6){
	// String _com=domain.substring(start+1,domain.length());
	// return _com;
	// }
	// }
	// }
	//
	// } catch (Exception e) {
	// log.error(e.getMessage(),e);
	// e.printStackTrace();
	// }
	// return "";
	// }
	public static String getNodeTxt(String fileName, String nodeName) {
		Properties pro = getProperties("/" + fileName);
		try {
			String val = pro.getProperty(nodeName);
			return val;
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage(), e);
		}
		return "";
	}

	public static void writer(String fileName, String content) {
		if (content == null || content.equals("")) {
			return;
		}
		try {
			FileWriter writer = new FileWriter(fileName, false);
			writer.write(content);
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static class SimpleHash {
		private final int cap;
		private final int seed;

		public SimpleHash(int cap, int seed) {
			this.cap = cap;
			this.seed = seed;
		}

		public int hash(String value) {
			int result = 0;
			int len = value.length();
			for (int i = 0; i < len; i++) {
				result = seed * result + value.charAt(i);
			}
			// if((cap - 1)<result){
			// log.error(result+" hashcode too long:"+value);
			// }
			return (cap - 1) & result;
		}
	}

	private final static float mNum = 64 / 5;
	private final static long size = (long)(1L * mNum * 1024 * 1024 * 8);

	/**
	 * 得到hashcode
	 *
	 * @param value
	 * @return int
	 */
	public static String getHashCode(String value) {
		long hash = 0;
		for (int i = 0; i < value.length(); i++) {
			hash = 31 * hash + value.charAt(i);
		}
		// if(size<hash){
		// log.error(hash+" hashcode too long:"+size);
		// }
		String hs = (hash % size) + "";
		if (hash < 0) {
			hash *= -1;
			hs = hs.replace("-", "O");
		}
		return hs;
	}

	private static final String regExtag = "[\\u4e00-\\u9fa5]";
	private static final Pattern ptag = Pattern.compile(regExtag);

	public static boolean ishanzi(String title) {
		Matcher m = ptag.matcher(title);
		boolean hanziflg = false;
		while (m.find()) {
			hanziflg = true;
			break;
		}
		return hanziflg;
	}

	public static String ascii2native(String theString) {

		char aChar;

		int len = theString.length();

		StringBuffer outBuffer = new StringBuffer(len);

		for (int x = 0; x < len;) {

			aChar = theString.charAt(x++);

			if (aChar == '\\') {

				aChar = theString.charAt(x++);

				if (aChar == 'u') {

					// Read the xxxx

					int value = 0;

					for (int i = 0; i < 4; i++) {

						aChar = theString.charAt(x++);

						switch (aChar) {

							case '0':

							case '1':

							case '2':

							case '3':

							case '4':

							case '5':

							case '6':
							case '7':
							case '8':
							case '9':
								value = (value << 4) + aChar - '0';
								break;
							case 'a':
							case 'b':
							case 'c':
							case 'd':
							case 'e':
							case 'f':
								value = (value << 4) + 10 + aChar - 'a';
								break;
							case 'A':
							case 'B':
							case 'C':
							case 'D':
							case 'E':
							case 'F':
								value = (value << 4) + 10 + aChar - 'A';
								break;
							default:
								throw new IllegalArgumentException("Malformed   \\uxxxx   encoding.");
						}

					}
					outBuffer.append((char)value);
				} else {
					if (aChar == 't')
						aChar = '\t';
					else if (aChar == 'r')
						aChar = '\r';

					else if (aChar == 'n')

						aChar = '\n';

					else if (aChar == 'f')

						aChar = '\f';

					outBuffer.append(aChar);

				}

			} else

				outBuffer.append(aChar);

		}

		return outBuffer.toString();

	}

	/**
	 * 去重复
	 *
	 * @param list
	 * @return List<String>
	 */
	public static List<String> format(List<String> list) {
		List<String> newlist = new ArrayList<String>();
		if (list == null || list.size() == 0) {
			return newlist;
		}
		for (int i = 0; i < list.size(); i++) {
			if (!newlist.contains(list.get(i))) {
				newlist.add(list.get(i));
			}
		}
		return newlist;
	}

	/**
	 * list转换成string
	 *
	 * @param list
	 * @param c
	 * @return String
	 */
	public static String formatString(List<String> list, String c) {
		if (list == null || list.size() == 0) {
			return "";
		}
		if (c == null) {
			c = " ";
		}
		String s = "";
		for (int i = 0; i < list.size(); i++) {
			if (i > 0) {
				s = s + c;
			}
			s = s + list.get(i);
		}
		return s;
	}

	/**
	 * 去掉头和尾的符号
	 *
	 * @param url
	 * @param c
	 * @return String
	 */
	public static String clearCharFormat(String url) {
		if (url != null && url.length() > 2) {
			char _c = url.charAt(url.length() - 1);
			if (_c == c_g) {
				return url.substring(0, url.length() - 1);
			}
		}
		return url;
	}

	/**
	 * 把子域名替换成*
	 *
	 * @param url
	 * @return String
	 */
	public static String getDomainX(String url) {
		String a = StringCommonUtils.getDomainLast(url);
		String b = StringCommonUtils.getDomainMain(url);
		String c = a.replace(b, "");
		if (c != null && !c.equals("")) {
			String d = url.replace("http://" + c, "http://*.");
			return d;
		}
		return url;
	}

	public static String getStartEnd(int size, Long start, Long end) {
		if (start >= end) {
			return "";
		}
		return " use:" + (end - start) + "ms " + ((1000 * size) / (end - start)) + "num/s";
	}

	public static String getStartEndSecond(int size, Long start, Long end) {
		if (start >= end) {
			return "";
		}
		return " use:" + ((end - start) / 1000) + "s " + ((1000 * size) / (end - start)) + "num/s";
	}

	public static List<List<?>> subList(List<?> objList, int rows) {
		// int rows = 100;// 解决写hbase速度慢的漏洞
		int uids = objList.size();
		int page = uids / rows;
		List<List<?>> rs = new Vector<List<?>>();
		for (int i = 1; i <= page + 1; i++) {
			int start = (i - 1) * rows;
			int end = (i) * rows;
			if (start >= uids) {
				break;
			}
			if (end >= uids) {
				end = uids;
			}
			List<?> data = objList.subList(start, end);
			rs.add(data);
		}
		return rs;
	}

	/**
	 * 去掉头和尾的符号
	 *
	 * @param url
	 * @param c
	 * @return String
	 */
	public static String clearCFormat(String url, char c) {
		if (url != null && url.length() > 2) {
			char _c1 = url.charAt(url.length() - 1);
			if (_c1 == c) {
				return url.substring(0, url.length() - 1);
			}

			char _c2 = url.charAt(0);
			if (_c2 == c) {
				return url.substring(1, url.length());
			}
		}
		return url;
	}

	/**
	 * 获取进程路径最后后的字符串
	 *
	 * @return String
	 */
	public static String getProcessName() {

		// String path=System.getProperty("user.dir");
		// if(path.indexOf("\\")>-1){
		// path=path.replace("\\","/");
		// }
		// path=path.replace("/shell", "");
		String path = getProcessDir();
		String s = path.substring(path.lastIndexOf("/") + 1, path.length());
		return s;
	}

	/**
	 * 获取进程路径最后后的字符串
	 *
	 * @return String
	 */
	public static String getProcessNamefromDir(String processDir) {
		String s = processDir.substring(processDir.lastIndexOf("/") + 1, processDir.length());
		return s;
	}

	public static String getProcessDir() {
		String os = System.getProperty("os.name");
		if (os.toLowerCase().indexOf("windows") > -1) {
			String path = System.getProperty("user.dir");
			if (path.indexOf("\\") > -1) {
				path = path.replace("\\", "/");
			}
			path = path.replace("/shell", "");
			return path;
		}
		String jp = System.getProperty("java.class.path");
		String arr[] = jp.split(":");
		String path = arr[0].replace("/conf", "");
		return path;
	}

	public static Boolean isWindos() {
		String os = System.getProperty("os.name");
		if (os.toLowerCase().indexOf("windows") > -1) {
			return true;
		}
		return false;
	}

	public static InetAddress getLocalHostLANAddress() throws UnknownHostException {
		try {
			InetAddress candidateAddress = null;
			// 遍历所有的网络接口
			for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); ifaces.hasMoreElements();) {
				NetworkInterface iface = (NetworkInterface)ifaces.nextElement();
				// 在所有的接口下再遍历IP
				for (Enumeration inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
					InetAddress inetAddr = (InetAddress)inetAddrs.nextElement();
					if (!inetAddr.isLoopbackAddress()) {// 排除loopback类型地址
						if (inetAddr.isSiteLocalAddress()) {
							// 如果是site-local地址，就是它了
							return inetAddr;
						} else if (candidateAddress == null) {
							// site-local类型的地址未被发现，先记录候选地址
							candidateAddress = inetAddr;
						}
					}
				}
			}
			if (candidateAddress != null) {
				return candidateAddress;
			}
			// 如果没有发现 non-loopback地址.只能用最次选的方案
			InetAddress jdkSuppliedAddress = InetAddress.getLocalHost();
			if (jdkSuppliedAddress == null) {
				throw new UnknownHostException("The JDK InetAddress.getLocalHost() method unexpectedly returned null.");
			}
			return jdkSuppliedAddress;
		} catch (Exception e) {
			UnknownHostException unknownHostException = new UnknownHostException("Failed to determine LAN address: " + e);
			unknownHostException.initCause(e);
			throw unknownHostException;
		}
	}

	public static String string2Unicode(String string) {
		StringBuffer unicode = new StringBuffer();
		for (int i = 0; i < string.length(); i++) {
			// 取出每一个字符
			char c = string.charAt(i);
			// 转换为unicode
			unicode.append(string2Unicode(c));
		}
		return unicode.toString();
	}

	public static final boolean isChineseChar(char c) {
		Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
		if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
			|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
			|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
			return true;
		}
		return false;
	}

	public static final boolean isChinese(String strName) {
		char[] ch = strName.toCharArray();
		for (int i = 0; i < ch.length; i++) {
			char c = ch[i];
			if (isChineseChar(c)) {
				return true;
			}
		}
		return false;
	}

	public static String getTimeStr(Date date) {
		if (date == null) {
			date = new Date();
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(date);
	}

	/**
	 * 把对象转成json [注:不能用在别处,Map等其他类型字段未处理]
	 *
	 * @param obj
	 * @return String
	 */
	public static String formatJson(Object obj) {
		try {
			StringBuffer buff = new StringBuffer();
			Class clazz = obj.getClass();
			Field[] fields = obj.getClass().getDeclaredFields();// 获得属性
			String[] arr_type =
				{"char", "long", "int", "class java.lang.Long", "class java.lang.Integer", "class java.lang.String", "class java.lang.Double", "class java.util.Date",
					"class java.sql.Timestamp", "class java.lang.Short", "class java.lang.Boolean", "class java.lang.Float"};
			String[] filterField = {"serialVersionUID", "class org.apache.log4j.Logger", "sameNum", "class java.util.Map"};
			for (Field field : fields) {
				field.setAccessible(true);
				String name = field.getName();
				// 过滤final修饰的类型
				if (Modifier.isFinal(field.getModifiers())) {
					continue;
				}
				// 已经处理过的字段类型
				Boolean field_type_done = false;
				for (int i = 0; i < arr_type.length; i++) {
					if (arr_type[i].equals(field.getType().toString())) {
						field_type_done = true;
						break;
					}
				}
				// 不在正常类型里
				if (!field_type_done) {
					Boolean print = true;
					// 不处理的类型
					for (int i = 0; i < filterField.length; i++) {
						if (field.getType().toString().equals(filterField[i])) {
							print = false;
							break;
						}
					}
					if (print) {
						// static不显示
						if (!Modifier.isStatic(field.getModifiers())) {
							log.info(field.getType().toString() + " field not add error !");
						}
					}
					continue;
				}
				try {
					PropertyDescriptor pd = new PropertyDescriptor(name, clazz);

					Method getMethod = pd.getReadMethod();// 获得get方法
					Object val = getMethod.invoke(obj);// 执行get方法返回一个Object
					if (val == null) {
						val = "";
					}
					if (field.getType().toString().equals("class java.lang.String")) {
						String str = val.toString();
						String newVal = string2Unicode(str);
						val = newVal;
					} else if (field.getType().toString().equals("class java.util.Date")) {
						if (!val.equals("")) {
							val = getTimeStr((Date)val);
							val = string2Unicode(val.toString());
						}
					} else if (field.getType().toString().equals("class java.sql.Timestamp")) {
						if (!val.equals("")) {
							java.sql.Timestamp time = (java.sql.Timestamp)val;
							val = getTimeStr(new Date(time.getTime()));
							val = string2Unicode(val.toString());
						}
					}
					buff.append("\"" + name + "\"");
					buff.append(":\"" + val + "\",");
				} catch (IntrospectionException e) {
					e.printStackTrace();
					log.error(e.getMessage(), e);
					continue;
				}
			}
			String res = buff.toString().trim();
			if (res.charAt(res.length() - 1) == ',') {
				res = res.substring(0, res.length() - 1);
			}
			res = "{" + res + "}";
			return res;
		} catch (SecurityException e) {
			e.printStackTrace();
			log.error(e.getMessage(), e);
		} catch (IllegalArgumentException e) {
			log.error(e.getMessage(), e);
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
			log.error(e.getMessage(), e);
		} catch (InvocationTargetException e) {
			e.printStackTrace();
			log.error(e.getMessage(), e);
		}
		return "";
	}

	public static String string2Unicode(char c) {
		String str = Integer.toHexString(c) + "";
		int len = str.length();
		if (len < 4) {
			switch (len) {
				case 3:
					str = "0" + str;
					break;
				case 2:
					str = "00" + str;
					break;
				case 1:
					str = "000" + str;
					break;
			}
		}
		return "\\u" + str;
	}

	/**
	 * 获取host 不带www
	 *
	 * @param url
	 * @return
	 */
	public static String getHost(String url) {
		String newUrl = getDomain(url);
		if (newUrl.indexOf("//") > -1) {
			newUrl = newUrl.split("//")[1];
		}
		if (newUrl != null) {
			if (newUrl.indexOf("www.") == 0) {
				newUrl = newUrl.substring(4, newUrl.length());
			}
			// newUrl=newUrl.replace("www.","");
			// newUrl=newUrl.replace("https://www.","");
		}
		return newUrl;
	}

	public static String toHttp(String ss) {
		if (ss == null || ss.equals("")) {
			return ss;
		}
		if (ss.toLowerCase().indexOf("https://") == 0) {
			ss = "http://" + ss.substring(8, ss.length());
		}
		return ss;
	}

	/**
	 * 清掉微博昵称
	 *
	 * @param content
	 * @return List<String>
	 */
	public static String replaceWeiboNik(String content) {
		// 会有@切不出来的情况
		if (content.indexOf("@") > -1) {
			Matcher matcher = pattern_dv1.matcher(content);
			while (matcher.find()) {
				String tmp = matcher.group();
				if (!tmp.equals("")) {
					if (tmp.lastIndexOf("@") > 0) {
						String[] nicks = tmp.split("@");
						for (int i = 0; i < nicks.length; i++) {
							if (!nicks[i].equals("")) {
								content = content.replace("@" + nicks[i], "");
							}
						}
					} else {
						content = content.replace(tmp, "");
					}
				}
			}
			Matcher matcher2 = pattern_dv2.matcher(content);
			while (matcher2.find()) {
				String tmp = matcher2.group();
				if (!tmp.equals("")) {
					if (tmp.lastIndexOf("@") > 0) {
						String[] nicks = tmp.split("@");
						for (int i = 0; i < nicks.length; i++) {
							if (!nicks[i].equals("")) {
								content = content.replace("@" + nicks[i], "");
							}
						}
					} else {
						content = content.replace(tmp, "");
					}
				}
			}
			Matcher matcher3 = pattern_dv3.matcher(content);
			while (matcher3.find()) {
				String tmp = matcher3.group();
				if (!tmp.equals("")) {
					if (tmp.lastIndexOf("@") > 0) {
						String[] nicks = tmp.split("@");
						for (int i = 0; i < nicks.length; i++) {
							if (!nicks[i].equals("")) {
								content = content.replace("@" + nicks[i], "");
							}
						}
					} else {
						content = content.replace(tmp, "");
					}
				}
			}
		}
		return content;
	}

	public static String relaceHttp(String str) {
		if (str != null && str.indexOf("//") > -1) {
			str = str.trim() + " ";
			str = str.replaceAll("(https|http|HTTPS|HTTP)://[^\u4e00-\u9fa5,,，。 ;；:：'’\"“、]{4,1024}", "");
		}
		return str;
	}


	public static String clear(String contet, char c) {
		if ((contet != null) && (contet.length() > 0)) {
			if (contet.charAt(0) == c) {
				contet = contet.substring(1, contet.length());
			}
			if (contet.charAt(contet.length() - 1) == c) {
				contet = contet.substring(0, contet.length() - 1);
			}
		}
		return contet;
	}

	/**
	 * unicode转成汉字
	 *
	 * @param unicode
	 * @return String
	 */
	public static String unicode2String(String unicode) {

		StringBuffer string = new StringBuffer();

		String[] hex = unicode.split("\\\\u");

		for (int i = 1; i < hex.length; i++) {
			if (hex[i].length() == 4) {
				// 转换出每一个代码点
				int data = Integer.parseInt(hex[i], 16);
				// 追加成string
				string.append((char)data);
			} else {
				string.append(hex[i]);
				// String str=hex[i];
				// String subIndex=str.substring(0,4);
				// int data = Integer.parseInt(subIndex, 16);
				// // 追加成string
				// string.append((char) data);
				// string.append(str.substring(4,str.length()));
			}
		}
		return string.toString();
	}

	public static int searchZH(String s) {

		int result = -1;
		// 用Unicode码实现

		// 查找第一个汉字
		if (s == null || s.trim().length() == 0) {

			return result;
		}
		for (int index = 0; index <= s.length() - 1; index++) {
			// 将字符串拆开成单个的字符
			String w = s.substring(index, index + 1);
			if (w.compareTo("\u4e00") > 0 && w.compareTo("\u9fa5") < 0) {// \u4e00-\u9fa5 中文汉字的范围

				return index;

			}
		}
		return result;
		// // 找第一个中文符号
		// for (int index = 0; index <= s.length() - 1; index++) {
		// // 将字符串拆开成单个的字符
		// String w = s.substring(index, index + 1);
		// String reg = "【。，！？】";// 存放你要检测的中文符号
		// if (reg.indexOf(w) != -1) {//
		// System.out.println("第一个中文符号的索引位置：" + index + ",值为：" + w);
		// break;
		// }
		// }

	}

	public static List<String> removeOneWord(List<String> list) {
		List<String> restlist = new Vector<String>();
		for (String key : list) {
			if (key.length() == 1) {
				if (!restlist.contains(key)) {
					restlist.add(key);
				}
			} else {
				restlist.add(key);
			}
		}
		return restlist;
	}

	public static String listToString(List<String> list, String split_char) {
		if (list == null) {
			return null;
		}
		return StringUtils.join(list.toArray(), split_char);
	}

	public static List<String> StringToList(String string, String split_char) {
		if (string == null) {
			return null;
		}
		return Arrays.asList(string.split(split_char));
	}



	public static void main(String[] arr) {
		// List<String> listarea = FileUtils.readTxt("d:/content.txt", "unicode");
		//
		// Map<String, String> a = new HashMap<String, String>();
		//
		// String content = "";
		// for (int j = 0; j < listarea.size(); j++) {
		// content = listarea.get(j);
		//
		// }
		//
		// content = content.replace(" ", "");
		// System.out.println("content=" + content.length());
		//
		// System.out.println("content=" + content);
		// System.out.println("content=" + content.length());
//		System.out.println(getDomainMainNoPort("http://sh.tousu.sina.com.cn:8080/dfdf/"));
//		System.out.println(getDomainLast("http://sh.tousu.sina.com.cn:8080/dfdf/"));
//		System.out.println(getDomainLastNoPort("http://sh.tousu.sina.com.cn:8080/dfdf/"));
		System.out.println(getRemoveHttpUrl("http://sh.tousu.sina.com.cn/dfdf/"));
		System.out.println(getRemoveHttpUrl("http://sh.tousu.sina.com.cn/"));
		System.out.println(getRemoveHttpUrl("https://sh.tousu.sina.com.cn/"));

	}
}
